
def solveSentences(AllList):
    """
    :param AllList:传进来一个[[word,sentence],[word,sentence],[word,sentence]....] 左边是word右边是 有word的sentence
    :return: 返回所有单词和分句[单词,分词]
    """
    WordDispersivesentens_List = []
    for oneList in AllList:
        ressection = []
        section = str(oneList[1]).split(" ")
        for item in section:
            if '.' in item or ',' in item or '!' in item or '?' in item or ':' in item:
                character = item[-1:]
                item = item[:-1]
                ressection.append(item)
                ressection.append(character)
            else:
                if (item != "" and item != None and item != " "):
                    ressection.append(item)
        WordSentence_group = [oneList[0],ressection]
        WordDispersivesentens_List.append(WordSentence_group)
    return WordDispersivesentens_List


"""
处理单个句子的函数
"""
def solveSen(sentence):
    """
    :param sentence: 传进来一个字符串
    :return: 一个字符串的List
    """
    ressection = []  #结果列表
    section = sentence.split(" ")
    for item in section:
        if '.' in item or ',' in item or '!' in item or '?' in item or ':' in item:
            character = item[-1:]
            # print(character)
            item = item[:-1]
            ressection.append(item)
            ressection.append(character)
        else:
            ressection.append(item)
    return ressection

# [词，句子]

def BIO(List = []):
    '''

    :param List:   [词,[分词,,,,,]]
    :return:[B,B,B...]
    '''
    finishedGroup = []
    oneBIOList = []
    i = 0  #标志是几个I
    Listword = str(List[0]).split(' ') #单词被分成list
    wordNum = len(Listword)   #拿出词个数 如果是1个词就是1 2个词就是2
    if wordNum == 1:  #单个词处理
        if(List[0] in List[1]):
            realindex = List[1].index(str(List[0]))  #readindex是索引
            #填充BIOList
            o = 'O'
            length = len(List[1])
            oneBIOList = [o for i in range(length)]
            oneBIOList[realindex] = 'B'
            for i in range(1, wordNum):
                oneBIOList[realindex + i] = 'I'
            finishedGroup.append([List[1],oneBIOList])
    else:
        if(Listword[0] in List[1]):
            realindex = List[1].index(str(Listword[0]))  # readindex是索引
            o = 'O'
            # 填充BIOList
            length = len(List[1])
            oneBIOList = [o for i in range(length)]
            oneBIOList[realindex] = 'B'
            for i in range(1, wordNum):
                try:
                    oneBIOList[realindex + i] = 'I'
                except BaseException:
                    print("发生错误的位置为赋值第" + str(i) +"个词为I" + "完整词分词为" + str(oneBIOList) + "BIO为" + Listword[0] + "分词为" + str(List[1]) + "单词为" + List[0])
        else:
            print(str(List[1])+" "+str(Listword))

        #在此处更改返回值
        # finishedGroup.append([List[1], oneBIOList])
    return oneBIOList
print(BIO(['ab c',['a','ab','c','d']]))

